Conditions | 5 |
Total Lines | 18 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | function hideAllButCurrent(){ |
||
2 | //by default all submenut items are hidden |
||
3 | //but we need to rehide them for search |
||
4 | document.querySelectorAll("nav > ul > li > ul li").forEach(function(parent) { |
||
5 | parent.style.display = "none"; |
||
6 | }); |
||
7 | |||
8 | //only current page (if it exists) should be opened |
||
9 | var file = window.location.pathname.split("/").pop().replace(/\.html/, ''); |
||
10 | document.querySelectorAll("nav > ul > li > a").forEach(function(parent) { |
||
11 | var href = parent.attributes.href.value.replace(/\.html/, ''); |
||
12 | if (file === href) { |
||
13 | parent.parentNode.querySelectorAll("ul li").forEach(function(elem) { |
||
14 | elem.style.display = "block"; |
||
15 | }); |
||
16 | } |
||
17 | }); |
||
18 | } |
||
19 | |||
20 | hideAllButCurrent(); |